clear all;
close all;
clc

% Subject ID: 63, 64, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80

Subjects = {'63'};

fingers = 'abcde';
finger_names = {'Thumb';'Index';'Middle';'Ring';'Pinky'};

for isubject = 1:length(Subjects)
    Sub = Subjects{isubject}
%     file_save = ['Save_EMG_NN_result\' Sub '_CM.mat'];
    load pc_all_EEGgamma_withCM
    % ==================== Plot CM =============================
    f1 = figure('position',[100 100 700 350]);
    subplot(121)
    f_plotCM(CM_all{1},100);
    colormap(flipud(gray(256)));
    colorbar;
    CM_test=CM_all{1};
    title('A. Gamma-EEG Confusion Matrix');
    xlabel('True Finger');
    ylabel('Classified Finger');
    h = colorbar;
    h.Label.String = "Accuracy (%)";
    h.Label.Rotation = 270;
    h.Label.VerticalAlignment = "bottom";

    subplot(122)
    a_finger_test = diag(CM_test)./sum(CM_test)'*100;
    bar(a_finger_test,'facecolor',[0.5 0.5 0.5]);
    for ifinger=1:5
        pci(ifinger) = f_confid_I(20*20,a_finger_test(ifinger)/100,0.05);
    end
    hold on;
    errorbar(1:5,a_finger_test,pci*100,'.k');
    set(gca,'XTickLabel',finger_names);
    title('B. Gamma-EEG Performance');
    ylabel('Accuracy (%)');
    ylim([0 100]);
    xlabel('True Finger');
    hold on;
    plot([0 6],[20 20],'k');
    axis square
    box off
    hold off;
    clear CM_test PC_subject;
end
exportgraphics(f1,'Figure9_EEG_example.png','Resolution',300);

for i=[1 2 3 5]
p1=a_finger_test(i)./100;
p2=a_finger_test(4)./100;
N1=400;N2=400;
out = f_ztest(p1,p2,N1,N2)
end

